package com.hooper.dp.config;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.hooper.dp.dto.Result;
import com.hooper.dp.exception.BusinessException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
@RestControllerAdvice
public class WebExceptionAdvice {

    @ExceptionHandler(BusinessException.class)
    public Result handleRuntimeException(BusinessException e) {
        log.error(e.toString(), e);
        String description = StringUtils.isBlank(e.getDescriptions()) ? "" : e.getDescriptions();
        return Result.fail(e.getMessage() + "  " + description);
    }

    @ExceptionHandler(RuntimeException.class)
    public Result handleRuntimeException(RuntimeException e) {
        log.error(e.toString(), e);
        return Result.fail("服务器异常");
    }


}
